﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Data.Entity;
using OnlineMealOrdering.Persistence;
using OnlineMealOrdering.Common;
using OnlineMealOrdering.Domain;


namespace OnlineMealOrdering.Persistence
{
    public class OnlineStoreDbInitializer : DropCreateDatabaseIfModelChanges<OnlineStoreDbContext>
    {
        protected override void Seed(OnlineStoreDbContext context)
        {
            InitializeRole(context);
            InitializeUser(context);
        }

        void InitializeUser(OnlineStoreDbContext ctx)
        {
        }

        void InitializeRole(OnlineStoreDbContext ctx)
        {
            CreateRole(ctx, RolesDefinition.ConsumerRoleCode, RolesDefinition.ConsumerRoleName);
            CreateRole(ctx, RolesDefinition.StoreOnlineRoleCode, RolesDefinition.StoreOnlineRoleName);
            CreateRole(ctx, RolesDefinition.VIP1RoleCode, RolesDefinition.VIP1RoleName);
            CreateRole(ctx, RolesDefinition.Vip2RoleCode, RolesDefinition.Vip2RoleCode);
        }

        void CreateUser(OnlineStoreDbContext ctx, string userCode, string userName, string password, string roleCode)
        {
            //password = EncryptHelper.EncryptUserPassword(password);
            //ctx.Users.Add(UserEntity.CreateUser(userCode, userName, password, new List<string>() { roleCode}));
            //ctx.SaveChanges();
        }

        void CreateRole(OnlineStoreDbContext ctx, string roleCode, string roleName)
        {
            ctx.Roles.Add(RoleEntity.CreateRole(roleCode, roleName));
            ctx.SaveChanges();
        }

    }
}
